<template>
	<view class="page">
		<view class="top-view">
			<view class="swiper-wrap">
				<u-swiper :height="88" :list="swiperList" @click="clickSwiper" keyName="img"></u-swiper>
			</view>
			<view class="find">
				<view class="find-item" @click="sendBtn(0)">
					<image class="find-bg" src="../../../static/img/im-img-1.png"></image>
					<view class="find-content">
						<view class="f-name">
							寻找经销商
						</view>
						<view class="f-desc">
							精准对接，效果提升
						</view>
						<view class="f-btn red flexAJC">
							抢客户
						</view>
					</view>
				</view>
				<view class="find-item" @click="sendBtn(1)">
					<image class="find-bg" src="../../../static/img/im-img-2.png"></image>
					<view class="find-content">
						<view class="f-name">
							寻找厂家
						</view>
						<view class="f-desc">
							实时在线，抢占商机
						</view>
						<view class="f-btn blue flexAJC">
							抢代理
						</view>
					</view>
				</view>
			</view>
			<view class="search-wrap flexACB">
				<view class="search-item" @click="provincesShow = true">
					<view class="text">
						{{queryParams.province||'地区'}}
					</view>
					<image class="down" src="../../../static/img/icon-down.png" mode="widthFix"></image>
				</view>
				<view class="search-item" @click="chooseHy">
					<view class="text">
						{{queryParams.type?queryParams.typeName : '行业筛选'}}
					</view>
					<image class="down" src="../../../static/img/icon-down.png" mode="widthFix"></image>
				</view>
				<view class="search-item">
					<view class="text">
						产业链信息
					</view>
				</view>
				<view class="search-item" @click="toMap">
					<view class="text">
						地图浏览
					</view>
				</view>
			</view>
		</view>
		<view class="main">
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="top">
					<view class="tx-wrap">
						<image v-if="item.headImg" class="tx" :src="fileServer+item.headImg" mode="aspectFill"></image>
						<image v-else class="tx" src="../../../static/logo.png"></image>
						<view class="xz flexAJC">
							<view class="dian">

							</view>
							在线
						</view>
					</view>
					<view class="user">
						<view class="name-wrap flexACB">
							<view class="name-left flexAC">
								<view class="name">
									{{item.memberName}}
								</view>
								<view class="label">
									{{item.position}}
								</view>
								<image v-if="item.sfVip" class="vip" src="../../../static/img/vip-icon.png" mode="widthFix"></image>
								<!-- 0-经销商；1-厂家；2-产业链 -->
								<view v-if="item.type==0" class="dept">
									经销商
								</view>
								<view v-if="item.type==1" class="dept">
									厂家
								</view>
								<view v-if="item.type==2" class="dept">
									产业链
								</view>
							</view>
							<view class="talk-btn flexAJC">
								<image class="icon" mode="widthFix" src="../../../static/img/liaoyilia-green.png">
								</image>
								聊聊
							</view>
						</view>
						<view class="ads">
							<image class="icon" src="../../../static/img/gongsi.png" mode="widthFix"></image>
							{{item.companyName||'--'}}
						</view>
					</view>
				</view>
				<view class="content">
					主营品牌产品：{{item.zypphcp}}等
				</view>
				<view class="content-text">
					{{item.content}}
				</view>
				<view class="img-list" v-if="item.productImg&&item.imgList.length">
					<image class="img" mode="aspectFill" :src="fileServer+itemIn" v-for="(itemIn,i) in item.imgList" :key="i"></image>
				</view>
			</view>
			<u-empty v-if="status!='loading'&&list.length==0"
			        mode="data"
			        icon="http://cdn.uviewui.com/uview/empty/list.png"
			>
			</u-empty>
			
			<u-loadmore :status="status" v-else />
		</view>
		<view class="fb-btn flexAJC" @click="goSend">
			<image class="icon" src="../../../static/img/fabubiaoshu.png" mode="widthFix"></image>
			发布
		</view>
		<u-picker :show="provincesShow" :columns="provinces" @cancel="provincesShow = false"
			@confirm="chooseProvinces"></u-picker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileServer: this.$fileServer,
				swiperList: [],
				queryParams: {
					province: '',
					type:'',
					typeName:'',
					hyfl: '',//行业分类
				},
				list:[],
				status:'loading',//loading / nomore
				pageIndex:1,
				total:0,
				provinces: getApp().globalData.provincesList,//产地
				provincesShow: false,
				
			};
		},
		onLoad() {
			this.getBanner();
			this.getList();
		},
		methods: {
			// 地区
			chooseProvinces(e) {
				console.log(e)
				this.queryParams.province = e.value[0]
				this.provincesShow = false;
				this.pageIndex = 1;
				this.getList()
			},
			getBanner(){
				this.$api.member.getBannerList({type:1}).then(res => {
					if(res.flag){
						let list = res.data;
						list.forEach(ele=>{
							ele.img = this.fileServer +ele.img;
						})
						this.swiperList =list;
					}
				})
			},
			getList(){
				// hyfl 行业分类
				// loginMemberId 当前登录人ID
				// memberId 
				// pageIndex 
				// province  省份
				this.status = 'loading';
				let pageIndex = this.pageIndex;
				let loginMemberId = uni.getStorageSync("memberId");
				let queryParams = {...this.queryParams,pageIndex,loginMemberId,notToken:true}
				this.$api.duijie.getGxfbList(queryParams).then(res => {
					uni.stopPullDownRefresh(); // 关闭下拉刷新 
					if(res.code==200){
						let list = res.rows;
						list.forEach(ele=>{
							if(ele.productImg){
								ele.imgList = ele.productImg.split(',')
							}else{
								ele.imgList = []
							}
						})
						if(pageIndex==1){
							this.list = list
						}else{
							this.list = this.list.concat(list)
						}
						this.total = res.total;
						if(this.list.length<res.total){
							this.status = 'loadmore';
						}else{
							this.status = 'nomore';
						}
					}
				})
				
				
			},
			// 行业筛选
			chooseHy() {
				uni.showActionSheet({
					itemList: getApp().globalData.typeList.map(i => {
						return i.label
					}),
					success: (res) => {
						this.queryParams.type = getApp().globalData.typeList[res.tapIndex].value
						this.queryParams.typeName = getApp().globalData.typeList[res.tapIndex].label
						this.pageIndex = 1
						this.getList()
					}
				})
			},
			goSend(){
				uni.navigateTo({
					url:'/pages/mine/issueAdd/issueAdd'
				})
			},
			sendBtn(type){
				// type 寻找经销商 寻找厂家
				this.$api.member.getMemberInfo().then(res => {
					let member = res.data.member;
					if(member.type!=type){
						this.saveGxfbNoImg(type);
					}else{
						let tit = '请寻找'+(type==0?'厂家':'经销商')
						uni.showToast({
							title: tit,
							icon: "none"
						})
					}
				})
			},
			saveGxfbNoImg(type){
				this.$api.duijie.saveGxfbNoImg({type}).then(res => {
					uni.showToast({
						title: res.msg,
						icon: "none"
					})
				})
			},
			toMap() {
				uni.navigateTo({
					url: "/pages/client/mapMemo/mapMemo?type=ssdj"
				})
			},
			
			clickSwiper() {},
		},
		//上拉加载
		onReachBottom() {
			if(this.status == 'nomore'){
				return false
			}
			this.pageIndex++;
			this.getList();
		},
		onPullDownRefresh () {
		  this.pageIndex = 1;
		  this.getList();
		},
	}
</script>

<style lang="scss" scoped>
	.page {
		background-color: #F5F5F5;min-height: 100vh;

		.top-view {
			width: 100%;
			background-color: #fff;
			padding: 20rpx 32rpx 0;

			.find {
				display: flex;
				justify-content: space-between;
				margin-top: 20rpx;

				.find-item {
					position: relative;
					width: 336rpx;
					height: 170rpx;

					.find-bg {
						position: absolute;
						width: 100%;
						height: 100%;
						left: 0;
						top: 0;
						z-index: 1;
					}

					.find-content {
						position: relative;
						z-index: 2;
						width: 100%;
						height: 100%;
						padding: 16rpx 16rpx 0;

						.f-name {

							font-size: 32rpx;
							font-weight: bold;
							margin-bottom: 5rpx;
						}

						.f-desc {

							line-height: 34rpx;
							color: #777777;
						}

						.f-btn {
							margin-top: 10rpx;
							width: 124rpx;
							height: 50rpx;

							border-radius: 25rpx;
							color: #FFFFFF;

							&.red {
								background: #E96056;
							}

							&.blue {
								background: #69A9FF;
							}
						}
					}
				}
			}

			.search-wrap {
				width: 100%;
				padding: 28rpx 0 24rpx;

				.search-item {
					height: 44rpx;
					display: flex;
					align-items: center;

					.text {
						line-height: 44rpx;
						max-width: 150rpx;
						color: #333;
						font-size: 32rpx;margin-right: 5rpx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;
					}

					.down {
						width: 22rpx;
						height: auto;
					}
				}
			}
		}

		.main {
			width: 100%;
			padding: 24rpx 32rpx;

			.list {
				width: 100%;
				background: #FFFFFF;
				border-radius: 16rpx;
				margin-bottom: 38rpx;
				padding: 18rpx 24rpx 20rpx 16rpx;

				.top {
					display: flex;

					.tx-wrap {
						position: relative;
						width: 88rpx;
						height: 88rpx;

						.tx {
							width: 88rpx;
							height: 88rpx;
							border-radius: 50%;
						}

						.xz {
							position: absolute;
							z-index: 2;
							width: 60rpx;
							height: 28rpx;
							background: #C1E4C6;
							border-radius: 14rpx;
							font-size: 18rpx;
							color: #48B547;
							bottom: -14rpx;
							left: 50%;
							transform: translateX(-50%);

							.dian {
								width: 4rpx;
								height: 4rpx;
								background: #48B547;
								border-radius: 50%;
								margin-right: 4rpx;
							}
						}
					}

					.user {
						width: calc(100% - 88rpx);
						padding-left: 16rpx;

						.name-wrap {
							.name-left {
								line-height: 44rpx;

								.name {

									font-size: 32rpx;
									font-weight: bold;
									margin-right: 10rpx;
								}

								.label {
									font-size: 24rpx;
									color: #AAAAAA;
									margin-right: 6rpx;
								}

								.vip {
									width: 28rpx;
									height: auto;
									margin-left: 6rpx;
								}

								.dept {
									height: 36rpx;
									border-radius: 18rpx;
									background: #FFE9E9;
									color: #E83149;
									font-size: 20rpx;
									padding: 0 20rpx;
									line-height: 36rpx;
									margin-left: 6rpx;
								}
							}

							.talk-btn {
								width: 120rpx;
								height: 50rpx;
								background: #16C40B;
								border-radius: 25rpx;
								color: #FFFFFF;display: flex;align-items: center;

								.icon {
									width: 24rpx;
									height: auto;margin-right: 4rpx;margin-top: 5rpx;
								}
							}
						}

						.ads {
							color: #777777;
							font-size: 28rpx;
							line-height: 40rpx;

							.icon {
								display: inline-block;
								width: 24rpx;
								height: auto;
								margin-right: 6rpx;
							}
						}
					}
				}
			}

			.content {
				color: #AAAAAA;
				line-height: 40rpx;
				font-size: 28rpx;
				margin-bottom: 10rpx;
				margin-top: 22rpx;
			}

			.content-text {
				padding: 20rpx 0 0 0;
				font-size: 28rpx;
				border-top: 1px solid #F0F0F0;
			}

			.img-list {
				overflow: hidden;
				width: 100%;

				.img {
					width: 200rpx;
					height: 200rpx;
					margin-right: 22rpx;
					margin-top: 20rpx;
					border-radius: 16rpx;

					&:nth-child(3n+0) {
						margin-right: 0;
					}
				}
			}

		}

		.fb-btn {
			position: fixed;
			right: 14rpx;
			bottom: 24rpx;
			width: 164rpx;
			height: 70rpx;
			background: #EC2424;
			box-shadow: 1px 6 8rpx 0px rgba(236, 36, 36, 0.33);
			border-radius: 35rpx;
			z-index: 99;

			color: #FFFFFF;
			font-size: 26rpx;

			.icon {
				width: 30rpx;
				height: auto;
				margin-right: 4rpx;
			}
		}
	}
</style>